package com.palpiteiro.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.palpiteiro.bean.IBean;

public abstract class IDAO {
	
	protected Connection conn = null;

	private String user;
	
	public void setUser(String user){ this.user = user; }
	protected String getUser(){ return user; }
	
	public Connection getConn() throws SQLException{
		if(conn == null)
			try {
				Class.forName("org.postgresql.Driver");
	            conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/BD_Palpiteiro","postgres", "admin");  
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			}
		return conn;
	}
	
	public void setConn(Connection conn) {
		this.conn = conn;
	}
	
	public void closeConn() throws SQLException{
		this.conn.close();
	}
	
	public abstract ResultSet select(IBean bean) throws SQLException;
	
	public abstract void insert(IBean bean) throws SQLException;
	
	public abstract void update(IBean bean) throws SQLException;
}
